/**
 * Predefined variables
 * Name = SettingLayer
 * DateTime = Mon Jan 17 2022 15:27:44 GMT+0800 (中国标准时间)
 * Author = Created by zhj9922
 * FileBasename = SettingLayer.ts
 * gitee： https://gitee.com/coyeking
 */
import { UiBase } from '../../uiBase';
 
import { _decorator, Node,Slider ,game,sys} from 'cc';
const { ccclass, property } = _decorator;
import { audioManager } from '../../../framework/audioManager';
import { constant } from '../../../define/constant';
import { notifyEvent } from '../../../framework/notifyEvent';
 
@ccclass('SettingLayer')
export class SettingLayer extends UiBase {
    @property({
        type: Slider,
        displayName:'音乐',
    })
    public ui_music_slider: Slider = null;

    @property({
        type: Slider,
        displayName:'音效',
    })
    public ui_sound_slider: Slider = null;

    
    onEnable () {
        super.onEnable();
        this.ui_music_slider.progress = audioManager.instance.musicVolume;
        this.ui_sound_slider.progress = audioManager.instance.soundVolume;
        
        let hallBg = sys.localStorage.getItem(constant.LOCAL_STORAGE.hallBaindex);
    };

    /**
     * 按钮点击事件
     * @param event 
     * @param customEventData 
     */
	private onClick (event: Event, customEventData: string) {
        
        if (customEventData == 'close'){
            audioManager.instance.playSound();
            this.closeAction();
            return;
        }else if (customEventData == 'endgame'){
            audioManager.instance.playSound();
            game.end();
            return;
        }else if(customEventData == 'music_slider'){//调节背景音乐
            audioManager.instance.setMusic(this.ui_music_slider.progress);
            return;
        }else if(customEventData == 'sound_slider'){//调节音效
            audioManager.instance.setSound(this.ui_sound_slider.progress);
            return;
        }
        
        audioManager.instance.playSound();
        let hallBg = sys.localStorage.getItem(constant.LOCAL_STORAGE.hallBaindex);
        if (hallBg == customEventData) return;
        
        sys.localStorage.setItem(constant.LOCAL_STORAGE.hallBaindex,customEventData)
        
        notifyEvent.dispatchEvent(constant.NOTIFY_EVENT.USER_TOKEN);

        
    }
    
}

